package com.flyxiang.doc.utils;

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

/**
 * 文件转换工具类
 */
@Slf4j
public class DocConvertUtil {


    public static void wordToPdf(MultipartFile inputWord) {

        File inFile = new File("T:\\1_业主联名和注册表(1).docx");
        try (InputStream inputStream = new FileInputStream(inFile)) {
            Document doc = new Document(inputStream);
            doc.save("T:/test.pdf", SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("转换完毕==");
    }

    public static void wordToPdf1(MultipartFile multipartFile) {
//        File inputWord = new File("T:\\1_业主联名和注册表(1).docx");
//        File outputFile = new File("T:/test.pdf");
//        try  {
//            InputStream docxInputStream = new FileInputStream(inputWord);
//            OutputStream outputStream = new FileOutputStream(outputFile);
//            IConverter converter = LocalConverter.builder().build();
//            converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
//            outputStream.close();
//            System.out.println("success");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

    public static void main(String[] args) {
        wordToPdf(null);
    }
}
